#include<iostream>
using namespace std;
#include<vector>
#include<unordered_map>
#include<queue>


bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {

	vector<int> n(numCourses,0);

	unordered_map<int, vector<int>> hash;

	for (auto a : prerequisites)
	{
		int x1 = a[0], y1 = a[1];
		n[x1]++;
		hash[x1].push_back(y1);
	}

	queue<int> q;

	for (int i = 0; i < numCourses;i++)
	{
		if (n[i] == 0)q.push(i);
	}
	while (q.size())
	{
		int sz = q.size();
		for (int i = 0; i < sz; i++)
		{
			int number = q.front();
			q.pop();
			for (auto &a : hash)
			{
				for (auto b : a.second)
				{
					if (number == b)
					{
						n[a.first]--;
						if (n[a.first] == 0)
						{
							q.push(a.first);
						}
					}
					
				}
			}
		}

	}
	for (auto a : n)
	{
		if (a)return false;
	}
	return true;
}

int main()
{
	int n = 2;
	vector<vector<int>> nums = { {0,1} };
	cout << canFinish(n, nums) << endl;

	return 0;
}